package type1;

import java.util.Random;

/**
 * @projectName: com.xiayuanxing.designPattern
 * @className: CanRaffleState
 * @author: xiayuanxing
 * @description: 可以抽奖状态
 * @date: 2022/1/23 16:48
 * @version: 1.0
 */
public class CanRaffleState extends State{
    //初始化时传入活动引用，扣除积分后改变其状态
    RaffleActivity activity;

    public CanRaffleState(RaffleActivity activity) {
        this.activity = activity;
    }


    //已经扣除了积分，不能再扣
    @Override
    public void deductMoney() {
        System.out.println("已经扣过积分了");
    }


    //可以抽奖,抽完奖后，根据实际情况，改成新的状态
    @Override
    public boolean raffle() {
        System.out.println("正在抽奖，请稍等！");

        Random random = new Random();
        int i = random.nextInt(10);
        //10%的中奖机会
        if (i==0){
            //改变活动状态为发放奖品context
            activity.setState(activity.getDispenseState());
            return true;
        }else {
            System.out.println("很遗憾没有抽中奖品！");
            activity.setState(activity.getNoRaffleState());
            return false;
        }
    }


    //不能发放奖品
    @Override
    public void dispensePrize() {
        System.out.println("没中奖，不能发放奖品");
    }
}
